<?php
/**
 * Created by PhpStorm.
 * User: 诗觞
 * Date: 2016/5/25
 * Time: 19:43
 */
include_once("configs.php");
include_once("mysql.func.php");
class Model{
    public $valueArray;
    public $isUpdate=false;
    function  __set($name, $value)
    {
        $this->valueArray[$name]=$value;
    }
    function  __get($name)
    {
        return isset($this->valueArray[$name])?$this->valueArray:null;
    }
    function save()
    {
        global $db;
        echo "qdqdqdqdqd";
        $table=get_class($this);
        $table=strtolower($table);      
        if($this->isUpdate){
            $db->update($table,$this->valueArray);
        }
        else
        {
            $db->insert($table,$this->valueArray);
            $this->isUpdate=true;
        }
    }
    static function getById($id)
    {
        global $db;
        $table=get_called_class();
        $table=strtolower($table);
        $sql="select * from $table where id=$id";
        $arr=$db->fetchOne($sql);
        $a=new $table();
        $a->isUpdate=true;
        $a->valueArray=$arr;
        return $a;
    }
}


class My_article extends Model{

}

$r1 = new  My_article();
$r1->name="adqdsda";
$r1->date="2016-05-18";
$r1->editer="lalada";
$r1->times=7;
$r1->content="dasdasdbakdadbaskdbak";
$r1->save(); 



?>